package com.home.cop.employee.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.home.cop.employee.mapper.EmployeeMapper;
import com.home.cop.employee.model.Employee;
import com.home.cop.employee.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public List<Employee> getEmployeeByPhone(String phone) {
        return employeeMapper.getEmployeeByPhone(phone);
    }

    @Override
    public Employee getEmployee(String account, String pwd) {
        return employeeMapper.getEmployee(account,pwd);
    }

    @Override
    public PageInfo<Employee> list(Map<String, Object> params, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(employeeMapper.list(params));
    }

    @Transactional
    @Override
    public void deleteEmployee(String account) {
        employeeMapper.deleteByPrimaryKey(account);
    }

    @Transactional
    @Override
    public void insert(Employee employee) {
        employeeMapper.insert(employee);
    }

    @Transactional
    @Override
    public void updateInfo(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
    }

    @Transactional
    @Override
    public void updateStatus(String account, Integer status) {
        employeeMapper.updateStatus(account,status);
    }

    @Transactional
    @Override
    public void updatePass(String account, String pass) {
        employeeMapper.updatePass(account,pass);
    }

    @Override
    public Integer countEmployeeByRole(String roleId) {
        return employeeMapper.countEmployeeByRole(roleId);
    }

    @Override
    public List<Employee> getEmployeeByInstId(Integer instId) {
        return employeeMapper.getEmployeeByInstId(instId);
    }
}
